package com.xiaogao.sys.controller;

import com.xiaogao.common.entity.PageData;
import com.xiaogao.common.entity.Result;
import com.xiaogao.security.annotation.HasPerm;
import com.xiaogao.sys.request.dict.type.AddParam;
import com.xiaogao.sys.request.dict.type.QueryParam;
import com.xiaogao.sys.request.dict.type.UpdateParam;
import com.xiaogao.sys.response.SysDictTypeResponse;
import com.xiaogao.sys.service.SysDictTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/dict/type")
public class SysDictTypeController {
    private final SysDictTypeService sysDictTypeService;

    @PostMapping("/list")
    public Result<PageData<SysDictTypeResponse>> querySelective(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                                @RequestParam(required = false, defaultValue = "30") Integer pageSize,
                                                                @RequestBody QueryParam queryParam){
        PageData<SysDictTypeResponse> pageData = sysDictTypeService.querySeletive(pageNum,pageSize,queryParam);
        return Result.success(pageData);
    }

    @HasPerm("sys:dict:type:add")
    @PostMapping("/add")
    public Result<Object> add(@RequestBody @Validated AddParam addParam) {
        sysDictTypeService.add(addParam);
        return Result.success();
    }

    @HasPerm("sys:dict:type:update")
    @PutMapping("/update")
    public Result<Object> update(@RequestBody @Validated UpdateParam updateParam) {
        sysDictTypeService.update(updateParam);
        return Result.success();
    }

    @HasPerm("sys:dict:type:delete")
    @PostMapping("/delete")
    public Result<Object> delete(@RequestBody List<String> ids) {
        sysDictTypeService.delete(ids);
        return Result.success();
    }
}
